package com.timo.rabbitmq.handler;

import com.rabbitmq.client.Channel;
import com.timo.constant.RabbitMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @Description: 类用途：
 * @Author: Timo
 * @Date: 2019/7/24 10:56
 */
@Slf4j
@Component
public class TopicHandler {


    @RabbitListener(queues = "foo.topic.queue")
    public void fooListener(String msg, Message message, Channel channel) {
        log.info("[foo_topic]:{}",msg);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    @RabbitListener(queues = "foo.insert.topic.queue")
    public void fooInsterListener(String msg, Message message, Channel channel) {
        log.info("[foo_insert_topic]:{}",msg);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitListener(queues = "foo.update.topic.queue")
    public void fooUpdateListener(String msg, Message message, Channel channel) {
        log.info("[foo_update_topic]:{}",msg);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitListener(queues = "foo.delete.topic.queue")
    public void fooDeleteListener(String msg, Message message, Channel channel) {
        log.info("[foo_delete_topic]:{}",msg);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
